package io.renren.modules.moyuFront.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.moyuData.entity.ChartData;
import io.renren.modules.moyuData.entity.KgmData;
import io.renren.modules.moyuFront.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.moyuFront.dao.FrontMoyuDao;
import io.renren.modules.moyuFront.service.FrontMoyuService;


@Service("frontMoyuService")
public class FrontMoyuServiceImpl extends ServiceImpl<FrontMoyuDao, FrontMoyuEntity> implements FrontMoyuService {
    @Autowired
    FrontMoyuDao frontMoyuDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FrontMoyuEntity> page = this.page(
                new Query<FrontMoyuEntity>().getPage(params),
                new QueryWrapper<FrontMoyuEntity>()
        );

        return new PageUtils(page);
    }


    @Override
    public DetailMoyu getDetail(Long moyuId) {
        return frontMoyuDao.getDetail(moyuId);
    }

    @Override
    public Map<String, Object> getCategoryCharacterList() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("moyuType", frontMoyuDao.getMoyuType());
        map.put("moyuFeatrue", frontMoyuDao.getMoyuFeatrue());
        return map;
    }

    @Override
    public PageUtils getMoyuList(Map<String, Object> params) {
        Page page = new Page();
//        System.out.println(params.get("currPage"));
        page.setCurrent(Long.parseLong((String) params.get("currPage")));
        page.setSize(Long.parseLong((String) params.get("pageSize")));
        Integer moyuId = null;

        if (params.get("moyuId") != null) {
            moyuId = Integer.parseInt((String) params.get("moyuId"));
        }
        IPage<DetailMoyu> page1 = frontMoyuDao.getMoyuList(page, (String) params.get("moyuName"), (String) params.get("moyuFeatrue"), (String) params.get("moyuType"), moyuId);
        frontMoyuDao.updateMoyuHits(moyuId);
        return new PageUtils(page1);

    }

    /**
     * 获取词云数据
     */
    @Override
    public Map<String, Object> getCiYun() {
        Map<String, Object> map = new HashMap<>();
        map.put("moyuId", frontMoyuDao.getMoyuId());
        map.put("moyuHits", frontMoyuDao.getMoyuHits());
        return map;
    }

    @Override
    public List<WorldCloudVo> getWorldCloud(){
        return frontMoyuDao.getWorldCloud();
    }

}
